package datastructure.hash;

/**
 * @Author yao.xiao
 * @Date 2025/8/15 10:04
 * @Description 赎金信
 */
public class LC383 {
    //判断 ransomNote 能不能由 magazine 里面的字符构成。每个字符只能用一次
    public boolean canConstruct(String ransomNote, String magazine) {
        int[] arr = new int[26];
        for (char c : magazine.toCharArray()) {
            arr[c - 'a'] += 1;
        }
        for (char c : ransomNote.toCharArray()) {
            arr[c - 'a'] -= 1;
            if (arr[c - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }
}
